<template>
	<view class="">
		<u-navbar title="设置" autoBack placeholder></u-navbar>
		<view class="p-2 bg-white flex align-center border-bottom" @click="$u.route('pages/user/accountsecurity')">
			<view class="font-28 text-light3F">账号与安全</view>
			<view class="ml-auto flex align-center">
				<u-icon name="arrow-right" ></u-icon>
			</view>
		</view>
		<view class="p-2 bg-white flex align-center border-bottom" @click="$u.route('pages/user/privacy')">
			<view class="font-28 text-light3F">隐私政策</view>
			<view class="ml-auto flex align-center">
				<u-icon name="arrow-right" ></u-icon>
			</view>
		</view>
		<view class="p-2 bg-white flex align-center border-bottom" @click="clearStorage">
			<view class="font-28 text-light7F">清除缓存</view>
			<view class="ml-auto flex align-center">
				<view class="font-28 text-main mr-1">{{storageSize}}</view>
				<u-icon name="arrow-right" ></u-icon>
			</view>
		</view>
		<view class="p-2 bg-white flex align-center border-bottom" @click="$u.route('pages/user/about')">
			<view class="font-28 text-light7F">关于我们</view>
			<view class="ml-auto flex align-center">
				<view class="font-28 text-main mr-1">Version{{appVersion}}</view>
				<u-icon name="arrow-right" ></u-icon>
			</view>
		</view>
		<view class="p-2 bg-white flex align-center border-bottom" @click="$u.route('pages/user/writeoffacount')">
			<view class="font-28 text-light7F">注销账号</view>
			<view class="ml-auto flex align-center">
				<u-icon name="arrow-right" ></u-icon>
			</view>
		</view>
		
		
		<view class="fixed-bottom flex align-center justify-center mb-5" @click="logout">
			<view class="logout flex align-center justify-center">退出登录</view>
		</view>
		
		
	</view>
</template>

<script>
	export default{
		data(){
			return{
				storageSize:'',
				appVersion:''
			}
		},
		onLoad() {
			this.appVersion = uni.$u.sys().appVersion
		},
		methods:{
			getStorageSize() {
				uni.getStorageInfo({
					success: (res) => {
						let size = res.currentSize
						if (size < 1024) {
							this.storageSize = size + ' KB';
						} else if (size / 1024 >= 1 && size / 1024 / 1024 < 1) {
							this.storageSize = Math.floor(size / 1024 * 100) / 100 + ' MB';
						}
			
					}
			
				})
			},
			clearStorage() {
				uni.showModal({
					title: '提示',
					content: '确定清除缓存吗?',
					confirmText: '立即清除',
					success(res) {
						if (res.confirm) {
							uni.clearStorageSync();
							//重新获取并显示清除后的缓存大小
							this.getStorageSize();
							uni.showToast({
								title: '清除成功'
							})
						}
					}
				})
			
			},
			logout(){
				uni.showModal({
					title: '提示',
					content: '确定要退出登录吗?',
					showCancel: true,
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if(res.confirm){
							uni.clearStorageSync('userinfo')
							uni.clearStorageSync('token')
							uni.redirectTo({
								url: '/pages/login/login'
							});
						}
					}
				});
			}
		}
	}
</script>

<style>
	.logout{
		width: 694rpx;
		height: 100rpx;
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		opacity: 1;
		font-size: 30rpx;
		font-family: Source Han Sans CN-Medium, Source Han Sans CN;
		font-weight: 500;
		color: #333333;
	}
</style>